﻿#include "ListWidgetItem.h"
#include "ElementTreeItem.h"
#include "qcustomplot.h"
ListWidgetItem::ListWidgetItem(const QString &text,ElementTreeItem * treeItem, QListWidget *listview)
    :QListWidgetItem(text,listview)
    ,mElementTreeItem(treeItem)
    ,mXData(mElementTreeItem->parent()->data())
    ,mYData(mElementTreeItem->data())
{
    
}

QVector<double>& ListWidgetItem::xData()
{
    return mXData;
}

QVector<double> &ListWidgetItem::yData()
{
    return mYData;
}

const QVector<double>& ListWidgetItem::xData() const{
    return mXData;
}
const QVector<double>& ListWidgetItem::yData() const{
    return mYData;
}

void ListWidgetItem::updateGraphData()
{
    if(!mElementTreeItem)
        return;
    auto xData =mElementTreeItem->parent()->data();
    for(double &num:xData){
        num-=mDT;
    }
    auto yData=mElementTreeItem->data();
    for(double &num:yData){
        num*=mA;
        num+=mB;
    }
    mGraph->setData(xData,yData);
    // mGraph->setPen(mDialogSetCurve->selectColor());
}

QString ListWidgetItem::name(){
    ElementTreeItem* p=mElementTreeItem->parent();
    if(!p){
        return mElementTreeItem->value(Qt::DisplayRole).toString();
    }
    return p->value(Qt::DisplayRole).toString()+"："+mElementTreeItem->value(Qt::DisplayRole).toString();
}
